<template>
  <div class="">
    <el-form :model="ruleForm" ref="ruleForm"
             :class="isEdit?'':'formItem'"
             :label-position="labelPosition" :inline="false">

      <el-card class="box-card" shadow="never">
        <div slot="header" class="header-card">
          <span class="header-card-title">财务审核信息反馈</span>
        </div>

        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="发票是否认证:" prop="isInvoiceAuth"
                          :rules="isEdit ? rules.isInvoiceAuth :[]">
              <el-select v-model="ruleForm.isInvoiceAuth" v-if="isEdit" style="width: 100%;"
                         placeholder="请选择发票是否认证">
                <el-option label="是" value="1">
                </el-option>
                <el-option label="否" value="2">
                </el-option>
              </el-select>
              <span v-else>
                {{ ruleForm.isInvoiceAuth == 1 ? '是' : ruleForm.isInvoiceAuth == 2 ? '否' : '' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="红字信息编码:" prop="redLetterCode"
                          :rules="isEdit && ruleForm.isInvoiceAuth == 1 ? rules.redLetterCode :[]">
              <el-input v-model="ruleForm.redLetterCode" v-if="isEdit" placeholder="请输入红字信息编码"></el-input>
              <span v-else>{{ ruleForm.redLetterCode }}</span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="24">
          <el-col :span="24">
            <el-form-item label="红字信息单:" prop="redLetterOss"
                          :rules="isEdit && ruleForm.isInvoiceAuth == 1 ? rules.redLetterOss :[]">
              <image-common v-model="ruleForm.redLetterOss" :limit="20" :disabled="!isEdit" :upType="2"/>
            </el-form-item>
          </el-col>
        </el-row>

      </el-card>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "finaceMessage", //财务审核
  props: {
    value: {
      type: Object,
      default: {},
    },
    state: {
      type: String,
      default: "",
    },
  },
  computed: {
    ruleForm: {
      get() {
        let that = this;
        const proxy = new Proxy(that.value, {
          get(target, key) {
            return Reflect.get(target, key);
          },
          set(target, key, value) {
            if (value) {
              that.handleClearValidate(key);
            }
            that.$emit("input", {...target, [key]: value});
            return true;
          },
        });
        return proxy;
      },
    },
    labelPosition() {
      if (this.state === "write") {
        return "top";
      } else {
        return "right";
      }
    },
    isEdit() {
      let bool;
      switch (this.state) {
        case "write":
          bool = true;
          break;
        case "disabled":
          bool = false;
          break;
        case "readonly":
          bool = false;
          break;
      }
      return bool;
    },
  },
  data() {
    return {
      rules: {
        isInvoiceAuth: [
          {required: true, message: "请选择发票是否认证", trigger: "change"},
        ],
        redLetterCode: [
          {
            required: true,
            message: "请输入红字信息编码",
            trigger: "blur"
          },
        ],
        redLetterOss: [
          {
            required: true,
            message: "请上传红字信息单",
            trigger: "blur"
          },
        ],
      },
    };
  },
  created() {
  },
  mounted() {
  },
  methods: {
    valid() {
      return new Promise((resolve) => {
        this.$refs.ruleForm.validate((valid) => {
          resolve(valid);
        });
      });
    },

    handleClearValidate(str) {
      this.$refs.ruleForm.clearValidate(str);
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/styles/cwgd/formScss.scss";

.elForm {
  .el-form-item {
    width: 100%;
  }
}
</style>



